<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of depthxyz</title>
  <meta name="keywords" content="depthxyz">
  <meta name="description" content="depthxyz computes the x,y, and z components of the location where each">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- ../menu.html trunk --><!-- menu.html utils -->
<h1>depthxyz
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>depthxyz computes the x,y, and z components of the location where each</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [exyz]=depthxyz(depthRaw,draft,pitchRaw,roll,heading,beamAngle,unitsID,x,y,elev,ens); </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> depthxyz computes the x,y, and z components of the location where each
 beam reflects from the streambed using the algorithm provided by Gary
 Murdock, RDI, 10-25-2002

 INPUT
 depthRaw - matrix of beam depths
 draft - draft of instrument
 pitchRaw - pitch vector from ADCP in degrees
 roll - roll vector from ADCP in degrees
 heading - heading vector from ADCP in degrees
 beamAngle - beam angle of instrument in degrees
 magvar - magnetic variation for site
 unitsID - units identifier
 x - x-coordinate(Easting) of center of ADCP
 y - y-coordinate(Northing) of center of ADCP
 elev - elevation of water-surface at ADCP
 ens - vector of ensemble numbers

 OUTPUT

 exyz - matrix with rows of ensembles and columns of x,y, and z

 David S. Mueller
 U.S. Geological Survey
 Office of Surface Water
 dmueller@usgs.gov
 
 June 29, 2006</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [exyz]=depthxyz(depthRaw,draft,pitchRaw,roll,heading,beamAngle,</a><span class="keyword">...</span>
0002     unitsID,x,y,elev,ens);
0003 <span class="comment">% depthxyz computes the x,y, and z components of the location where each</span>
0004 <span class="comment">% beam reflects from the streambed using the algorithm provided by Gary</span>
0005 <span class="comment">% Murdock, RDI, 10-25-2002</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% INPUT</span>
0008 <span class="comment">% depthRaw - matrix of beam depths</span>
0009 <span class="comment">% draft - draft of instrument</span>
0010 <span class="comment">% pitchRaw - pitch vector from ADCP in degrees</span>
0011 <span class="comment">% roll - roll vector from ADCP in degrees</span>
0012 <span class="comment">% heading - heading vector from ADCP in degrees</span>
0013 <span class="comment">% beamAngle - beam angle of instrument in degrees</span>
0014 <span class="comment">% magvar - magnetic variation for site</span>
0015 <span class="comment">% unitsID - units identifier</span>
0016 <span class="comment">% x - x-coordinate(Easting) of center of ADCP</span>
0017 <span class="comment">% y - y-coordinate(Northing) of center of ADCP</span>
0018 <span class="comment">% elev - elevation of water-surface at ADCP</span>
0019 <span class="comment">% ens - vector of ensemble numbers</span>
0020 <span class="comment">%</span>
0021 <span class="comment">% OUTPUT</span>
0022 <span class="comment">%</span>
0023 <span class="comment">% exyz - matrix with rows of ensembles and columns of x,y, and z</span>
0024 <span class="comment">%</span>
0025 <span class="comment">% David S. Mueller</span>
0026 <span class="comment">% U.S. Geological Survey</span>
0027 <span class="comment">% Office of Surface Water</span>
0028 <span class="comment">% dmueller@usgs.gov</span>
0029 <span class="comment">%</span>
0030 <span class="comment">% June 29, 2006</span>
0031 
0032     <span class="comment">% Correct draft for units</span>
0033     <span class="keyword">if</span> unitsID==<span class="string">'ft'</span>
0034             draft=double(draft)*0.0328083;
0035         <span class="keyword">else</span>
0036             draft=double(draft)*.01;
0037     <span class="keyword">end</span>;
0038     
0039     <span class="comment">% Depending on how you got here, elev may be a char array. Check and</span>
0040     <span class="comment">% convert if necessary</span>
0041     <span class="keyword">if</span> ischar(elev); elev = str2num(elev); <span class="keyword">end</span>;
0042         
0043     <span class="comment">% Create geo matrix of x, y, and elevation of transducers</span>
0044     geo=[x,y,-1.*repmat(draft,size(y))+elev];    
0045 
0046     <span class="comment">% Compute slant range of each beam</span>
0047     <span class="keyword">if</span> ischar(beamAngle)
0048         beamAngleR=str2double(beamAngle).*pi/180;
0049     <span class="keyword">else</span>
0050         beamAngleR=beamAngle.*pi/180;
0051     <span class="keyword">end</span>
0052     range=(depthRaw-draft)./cos(beamAngleR);
0053     
0054     <span class="comment">% Adjust heading, pitch, and roll</span>
0055     rollR=roll.*pi/180;
0056     pitchRawR=pitchRaw.*pi/180;
0057     headingR=heading.*pi/180;
0058     pitchR=atan(tan(pitchRawR).*cos(rollR));
0059 
0060     <span class="comment">% Compute sine and cosine values</span>
0061     ch=cos(headingR);
0062     sh=sin(headingR);
0063     cp=cos(pitchR);
0064     sp=sin(pitchR);
0065     cr=cos(rollR);
0066     sr=sin(rollR);
0067     
0068     <span class="comment">% Configure transformation vectors for east, north, and vertical</span>
0069     trans2e=[ch.*cr+sh.*sp.*sr sh.*cp ch.*sr-sh.*sp.*cr];
0070     trans2n=[-sh.*cr+ch.*sp.*sr ch.*cp -sh.*sr-ch.*sp.*cr];
0071     trans2u=[-cp.*sr sp cp.*cr];
0072     
0073     <span class="comment">% Create matrix to convert from slant range to xyz</span>
0074     rng2xyz=[-sin(beamAngleR) 0 -cos(beamAngleR);<span class="keyword">...</span>
0075               sin(beamAngleR) 0 -cos(beamAngleR);<span class="keyword">...</span>
0076               0 sin(beamAngleR) -cos(beamAngleR);<span class="keyword">...</span>
0077              0 -sin(beamAngleR) -cos(beamAngleR)];
0078     
0079     <span class="comment">% Compute xyz for each beam</span>
0080     beam1xyz=repmat(rng2xyz(1,:),size(range,1),1).*repmat(range(:,1),1,3);
0081     beam2xyz=repmat(rng2xyz(2,:),size(range,1),1).*repmat(range(:,2),1,3);
0082     beam3xyz=repmat(rng2xyz(3,:),size(range,1),1).*repmat(range(:,3),1,3);
0083     beam4xyz=repmat(rng2xyz(4,:),size(range,1),1).*repmat(range(:,4),1,3);
0084     
0085     <span class="comment">% Correct beam 1 xyz for heading, pitch, and roll and compute elevation</span>
0086     beam1enu(:,1)=ens;
0087     beam1enu(:,2)=sum(trans2e.*beam1xyz,2);
0088     beam1enu(:,3)=sum(trans2n.*beam1xyz,2);
0089     beam1enu(:,4)=sum(trans2u.*beam1xyz,2);
0090     beam1enu(:,2:4)=beam1enu(:,2:4)+geo;
0091     
0092     <span class="comment">% Correct beam 2 xyz for heading, pitch, and roll and compute elevation</span>
0093     beam2enu(:,1)=ens;
0094     beam2enu(:,2)=sum(trans2e.*beam2xyz,2);
0095     beam2enu(:,3)=sum(trans2n.*beam2xyz,2);
0096     beam2enu(:,4)=sum(trans2u.*beam2xyz,2);
0097     beam2enu(:,2:4)=beam2enu(:,2:4)+geo;
0098     
0099     <span class="comment">% Correct beam 3 xyz for heading, pitch, and roll and compute elevation</span>
0100     beam3enu(:,1)=ens;
0101     beam3enu(:,2)=sum(trans2e.*beam3xyz,2);
0102     beam3enu(:,3)=sum(trans2n.*beam3xyz,2);
0103     beam3enu(:,4)=sum(trans2u.*beam3xyz,2);
0104     beam3enu(:,2:4)=beam3enu(:,2:4)+geo;
0105     
0106     <span class="comment">% Correct beam 4 xyz for heading, pitch, and roll and compute elevation</span>
0107     beam4enu(:,1)=ens;
0108     beam4enu(:,2)=sum(trans2e.*beam4xyz,2);
0109     beam4enu(:,3)=sum(trans2n.*beam4xyz,2);
0110     beam4enu(:,4)=sum(trans2u.*beam4xyz,2);
0111     beam4enu(:,2:4)=beam4enu(:,2:4)+geo;
0112     
0113     <span class="comment">% Create final matrix</span>
0114     exyz=[beam1enu;beam2enu;beam3enu;beam4enu];
0115     exyz=sortrows(exyz,1);
0116</pre></div>
<hr><address>Generated on Wed 04-Jun-2014 14:21:02 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>